package com.ruoyi.web.controller.dcjk;

import java.util.Date;
import java.util.List;

import com.ruoyi.common.core.page.PageDomain;
import com.ruoyi.common.core.page.TableSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import com.dcjk.domain.DcjkUsert;
import com.dcjk.dto.DcjkUsertDto;
import com.dcjk.service.IDcjkUsertService;
import org.apache.dubbo.config.annotation.DubboReference;

/**
 * 测试用户Controller
 *
 * @author dcjk
 * @date 2021-09-07
 */
@Api("测试用户")
@RestController
@RequestMapping("/dcjk/usert")
public class DcjkUsertController extends BaseController
{
    @DubboReference
    private IDcjkUsertService dcjkUsertService;

    /**
     * 查询测试用户列表
     */
    @ApiOperation("查询测试用户列表")
    @PreAuthorize("@ss.hasPermi('dcjk:usert:list')")
    @GetMapping("/list")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "主键", dataTypeClass = Long.class),
            @ApiImplicitParam(name = "userId", value = "用户ID", dataTypeClass = Long.class),
            @ApiImplicitParam(name = "deptId", value = "部门ID", dataTypeClass = Long.class),
            @ApiImplicitParam(name = "userName", value = "用户账号", dataTypeClass = String.class),
            @ApiImplicitParam(name = "nickName", value = "用户昵称", dataTypeClass = String.class),
            @ApiImplicitParam(name = "userType", value = "用户类型（00系统用户）", dataTypeClass = String.class),
            @ApiImplicitParam(name = "email", value = "用户邮箱", dataTypeClass = String.class),
            @ApiImplicitParam(name = "phonenumber", value = "手机号码", dataTypeClass = String.class),
            @ApiImplicitParam(name = "sex", value = "用户性别（0男 1女 2未知）", dataTypeClass = String.class),
            @ApiImplicitParam(name = "avatar", value = "头像地址", dataTypeClass = String.class),
            @ApiImplicitParam(name = "password", value = "密码", dataTypeClass = String.class),
            @ApiImplicitParam(name = "status", value = "帐号状态（0正常 1停用）", dataTypeClass = String.class),
            @ApiImplicitParam(name = "delFlag", value = "删除标志（0代表存在 2代表删除）", dataTypeClass = String.class),
            @ApiImplicitParam(name = "loginIp", value = "最后登录IP", dataTypeClass = String.class),
            @ApiImplicitParam(name = "loginDate", value = "最后登录时间", dataTypeClass = Date.class),
            @ApiImplicitParam(name = "createBy", value = "创建者", dataTypeClass = String.class),
            @ApiImplicitParam(name = "createTime", value = "创建时间", dataTypeClass = Date.class),
            @ApiImplicitParam(name = "updateBy", value = "更新者", dataTypeClass = String.class),
            @ApiImplicitParam(name = "updateTime", value = "更新时间", dataTypeClass = Date.class),
            @ApiImplicitParam(name = "remark", value = "备注", dataTypeClass = String.class),
    })
    public TableDataInfo list(DcjkUsertDto dcjkUsert)
    {
        PageDomain pageDomain = TableSupport.buildPageRequest();
        Integer pageNum = pageDomain.getPageNum();
        Integer pageSize = pageDomain.getPageSize();
        dcjkUsert.setPageNum(pageNum);
        dcjkUsert.setPageSize(pageSize);
        List<DcjkUsert> list = dcjkUsertService.list(dcjkUsert);
        return getDataTable(list);
    }

    /**
     * 导出测试用户列表
     */
    @ApiOperation("导出测试用户列表")
    @PreAuthorize("@ss.hasPermi('dcjk:usert:export')")
    @Log(title = "测试用户", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "主键", dataTypeClass = Long.class),
            @ApiImplicitParam(name = "userId", value = "用户ID", dataTypeClass = Long.class),
            @ApiImplicitParam(name = "deptId", value = "部门ID", dataTypeClass = Long.class),
            @ApiImplicitParam(name = "userName", value = "用户账号", dataTypeClass = String.class),
            @ApiImplicitParam(name = "nickName", value = "用户昵称", dataTypeClass = String.class),
            @ApiImplicitParam(name = "userType", value = "用户类型（00系统用户）", dataTypeClass = String.class),
            @ApiImplicitParam(name = "email", value = "用户邮箱", dataTypeClass = String.class),
            @ApiImplicitParam(name = "phonenumber", value = "手机号码", dataTypeClass = String.class),
            @ApiImplicitParam(name = "sex", value = "用户性别（0男 1女 2未知）", dataTypeClass = String.class),
            @ApiImplicitParam(name = "avatar", value = "头像地址", dataTypeClass = String.class),
            @ApiImplicitParam(name = "password", value = "密码", dataTypeClass = String.class),
            @ApiImplicitParam(name = "status", value = "帐号状态（0正常 1停用）", dataTypeClass = String.class),
            @ApiImplicitParam(name = "delFlag", value = "删除标志（0代表存在 2代表删除）", dataTypeClass = String.class),
            @ApiImplicitParam(name = "loginIp", value = "最后登录IP", dataTypeClass = String.class),
            @ApiImplicitParam(name = "loginDate", value = "最后登录时间", dataTypeClass = Date.class),
            @ApiImplicitParam(name = "createBy", value = "创建者", dataTypeClass = String.class),
            @ApiImplicitParam(name = "createTime", value = "创建时间", dataTypeClass = Date.class),
            @ApiImplicitParam(name = "updateBy", value = "更新者", dataTypeClass = String.class),
            @ApiImplicitParam(name = "updateTime", value = "更新时间", dataTypeClass = Date.class),
            @ApiImplicitParam(name = "remark", value = "备注", dataTypeClass = String.class),
    })
    public AjaxResult export(DcjkUsertDto dcjkUsert)
    {
        List<DcjkUsert> list = dcjkUsertService.list(dcjkUsert);
        ExcelUtil<DcjkUsert> util = new ExcelUtil<DcjkUsert>(DcjkUsert.class);
        return util.exportExcel(list, "测试用户数据");
    }

    /**
     * 获取测试用户详细信息
     */
    @ApiOperation("获取测试用户详细信息")
    @PreAuthorize("@ss.hasPermi('dcjk:usert:query')")
    @GetMapping(value = "/{id}")
    @ApiImplicitParam(name = "id", value = "主键", required = true, dataTypeClass = Long.class, paramType = "path")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(dcjkUsertService.getById(id));
    }

    /**
     * 新增测试用户
     */
    @ApiOperation("新增测试用户")
    @PreAuthorize("@ss.hasPermi('dcjk:usert:add')")
    @Log(title = "测试用户", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "主键", dataTypeClass = Long.class),
            @ApiImplicitParam(name = "userId", value = "用户ID", dataTypeClass = Long.class),
            @ApiImplicitParam(name = "deptId", value = "部门ID", dataTypeClass = Long.class),
            @ApiImplicitParam(name = "userName", value = "用户账号", dataTypeClass = String.class),
            @ApiImplicitParam(name = "nickName", value = "用户昵称", dataTypeClass = String.class),
            @ApiImplicitParam(name = "userType", value = "用户类型（00系统用户）", dataTypeClass = String.class),
            @ApiImplicitParam(name = "email", value = "用户邮箱", dataTypeClass = String.class),
            @ApiImplicitParam(name = "phonenumber", value = "手机号码", dataTypeClass = String.class),
            @ApiImplicitParam(name = "sex", value = "用户性别（0男 1女 2未知）", dataTypeClass = String.class),
            @ApiImplicitParam(name = "avatar", value = "头像地址", dataTypeClass = String.class),
            @ApiImplicitParam(name = "password", value = "密码", dataTypeClass = String.class),
            @ApiImplicitParam(name = "status", value = "帐号状态（0正常 1停用）", dataTypeClass = String.class),
            @ApiImplicitParam(name = "delFlag", value = "删除标志（0代表存在 2代表删除）", dataTypeClass = String.class),
            @ApiImplicitParam(name = "loginIp", value = "最后登录IP", dataTypeClass = String.class),
            @ApiImplicitParam(name = "loginDate", value = "最后登录时间", dataTypeClass = Date.class),
            @ApiImplicitParam(name = "createBy", value = "创建者", dataTypeClass = String.class),
            @ApiImplicitParam(name = "createTime", value = "创建时间", dataTypeClass = Date.class),
            @ApiImplicitParam(name = "updateBy", value = "更新者", dataTypeClass = String.class),
            @ApiImplicitParam(name = "updateTime", value = "更新时间", dataTypeClass = Date.class),
            @ApiImplicitParam(name = "remark", value = "备注", dataTypeClass = String.class),
    })
    public AjaxResult add(@RequestBody DcjkUsertDto dcjkUsert)
    {
        dcjkUsert.setCreateBy(getUsername());
        dcjkUsert.setCreateTime(DateUtils.getNowDate());
        return toAjax(dcjkUsertService.save(dcjkUsert));
    }

    /**
     * 修改测试用户
     */
    @ApiOperation("修改测试用户")
    @PreAuthorize("@ss.hasPermi('dcjk:usert:edit')")
    @Log(title = "测试用户", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "主键", dataTypeClass = Long.class),
            @ApiImplicitParam(name = "userId", value = "用户ID", dataTypeClass = Long.class),
            @ApiImplicitParam(name = "deptId", value = "部门ID", dataTypeClass = Long.class),
            @ApiImplicitParam(name = "userName", value = "用户账号", dataTypeClass = String.class),
            @ApiImplicitParam(name = "nickName", value = "用户昵称", dataTypeClass = String.class),
            @ApiImplicitParam(name = "userType", value = "用户类型（00系统用户）", dataTypeClass = String.class),
            @ApiImplicitParam(name = "email", value = "用户邮箱", dataTypeClass = String.class),
            @ApiImplicitParam(name = "phonenumber", value = "手机号码", dataTypeClass = String.class),
            @ApiImplicitParam(name = "sex", value = "用户性别（0男 1女 2未知）", dataTypeClass = String.class),
            @ApiImplicitParam(name = "avatar", value = "头像地址", dataTypeClass = String.class),
            @ApiImplicitParam(name = "password", value = "密码", dataTypeClass = String.class),
            @ApiImplicitParam(name = "status", value = "帐号状态（0正常 1停用）", dataTypeClass = String.class),
            @ApiImplicitParam(name = "delFlag", value = "删除标志（0代表存在 2代表删除）", dataTypeClass = String.class),
            @ApiImplicitParam(name = "loginIp", value = "最后登录IP", dataTypeClass = String.class),
            @ApiImplicitParam(name = "loginDate", value = "最后登录时间", dataTypeClass = Date.class),
            @ApiImplicitParam(name = "createBy", value = "创建者", dataTypeClass = String.class),
            @ApiImplicitParam(name = "createTime", value = "创建时间", dataTypeClass = Date.class),
            @ApiImplicitParam(name = "updateBy", value = "更新者", dataTypeClass = String.class),
            @ApiImplicitParam(name = "updateTime", value = "更新时间", dataTypeClass = Date.class),
            @ApiImplicitParam(name = "remark", value = "备注", dataTypeClass = String.class),
    })
    public AjaxResult edit(@RequestBody DcjkUsertDto dcjkUsert)
    {
        dcjkUsert.setUpdateBy(getUsername());
        dcjkUsert.setUpdateTime(DateUtils.getNowDate());
        return toAjax(dcjkUsertService.updateById(dcjkUsert));
    }

    /**
     * 删除测试用户
     */
    @ApiOperation("删除测试用户")
    @PreAuthorize("@ss.hasPermi('dcjk:usert:remove')")
    @Log(title = "测试用户", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @ApiImplicitParam(name = "ids", value = "主键", required = true, dataTypeClass = List.class, paramType = "path")
    public AjaxResult remove(@PathVariable List<Long> ids)
    {
        return toAjax(dcjkUsertService.removeByIds(ids));
    }

}